requirejs(['serializeObject', 'art-template', 'moment'], function (_, template, moment) {
    $(document).ready(function () {
    });

    $('#dg').datagrid({
        method: 'post',
        striped: true,
        singleSelect: true,
        pageSize: 20,
        border: false,
        toolbar: '#tb',
        fit: true,
        rownumbers: true,
        pagination: true,
        queryParams: $("#searchForm").serializeObject(),
        onDblClickRow: function (rowIndex, row) {
        },
        onLoadSuccess: function () {
            var userType = $('#userType').val();
            if (userType == USER_TYPE.TEACHER) {//如果是老师,显示操作列
                $('#dg').datagrid('showColumn', 'operate');
            }
        },
        url: ctx + "/study/homeworkDetail/listCommittedPage",
        columns: [[
            {field: 'studentName', title: '学生姓名', width: 150},
            {
                field: 'updateDate', title: '提交时间',
                formatter: function (val, row, index) {
                    if(val){
                        return moment(val).format(DATE_FORMAT.DATE_FORMAT_YMD);
                    }
                }
            },
            {
                field: 'operate', title: '操作', align: 'center', hidden: true,
                formatter: function (val, row, index) {
                    var html = template("operateTemplate", row);
                    return html;
                }
            }
        ]]
    });

    /**
     * 查看学生作业
     */
    $(document).on('click', ".js-viewButton", function () {
        var homeworkDetailId = $(this).data('id');
        window.parent.addTab1('查看学生作业', ctx + '/study/homeworkDetail/page/view?id=' + homeworkDetailId);
    });

});

